//
// ActionManager.h
// Usage: Manage action register and remove, action include "exception action"
//        and "irq action"
// Create Date: 2009-02-17
// Creator: MaJiuyue
//
#ifndef _ACTION_MANAGER_H_
#define _ACTION_MANAGER_H_

#include <type.h>
#include <const.h>
#include <SCI.h>
#include "IRQAction.h"
#include "ExceptionAction.h"
#include "DefaultExceptionAction.h"

class CActionManager : public Callable
{
private:
	/* IRQAction list, one list per IRQ */
	IRQAction * irq_action_list[IRQ_NR];

	/* ExceptionAction, one action per exception */
	ExceptionAction * exception_action[EXCEPTION_NR];
	DefaultExceptionAction default_exception_action;

	/* System call*/
	
public:
	CActionManager();

	/* 
	 * Register an IRQAction to the designated irq, 
	 * caller should take care of action for latter remove
	 */
	bool RegisterIRQAction(u32 irq, IRQAction * action);
	/*
	 * Remove action from it's irq_action_list, 
	 * caller should provide `action' to be removed
	 */
	void RemoveIRQAction(IRQAction * action);

	/* 
	 * Register an ExceptionAction to the designated vector, 
	 * caller should take care of action for latter remove,
	 * old action will be lost.
	 */
	void RegisterExceptionAction(u32 vec_no, ExceptionAction * action);
	/*
	 * Remove action from vector, 
	 * caller should provide `action' to be removed
	 */
	void RemoveExceptionAction(ExceptionAction * action);

public:
	/* IRQ interrupt handler */
	void irq_handler(u32 irq, regs_t *regs);
	/* Exception handler */
	void exception_handler(u32 vec_no, u32 err_code, regs_t *regs);
	/* System call handler */
	void syscall_handler(regs_t *regs);
};

#endif

